#include "key.h"

struct keys key[4]={0,0,0,0};

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance==TIM4)
	{
		key[0].key_sta=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0);
		key[1].key_sta=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1);
		key[2].key_sta=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2);
		key[3].key_sta=HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0);
		for(int i=0;i<4;i++)
		{
			switch(key[i].key_qie)
			{
				case 0:
				{
					if(key[i].key_sta==0)
					{
						key[i].key_qie=1;
					}
				}
				break;
				case 1:
				{
					if(key[i].key_sta==0)
					{
						key[i].key_qie=2;
					}
					else
					{
						key[i].key_qie=0;
					}
				}
				break;
				case 2:
				{
					if(key[i].key_sta==1)
					{
						key[i].key_main=1;
						key[i].key_qie=0;
					}
				}
				break;
			}
		}
	}
}
double zhi1,zhi2;
unsigned int hz1;
float duty1;
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance==TIM2)
	{
		if(htim->Channel==HAL_TIM_ACTIVE_CHANNEL_1)
		{
			zhi1=HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);
			zhi2=HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_2);
			__HAL_TIM_SetCounter(htim,0);
			duty1=(zhi2/zhi1)*100;
			hz1=(80000000/80)/zhi1;
			HAL_TIM_IC_Start(htim,TIM_CHANNEL_1);
			HAL_TIM_IC_Start(htim,TIM_CHANNEL_2);
		}
	}
}
